<template>
	<view class="car-boxbox" v-if="cart.length !== 0">
		<!-- 收货地址 -->
		<my-add></my-add>
		<!-- 商品列表标题区域 -->
		<view class="cart-title">
			<!-- z左侧图标 -->
			<uni-icons type="shop" size="18"></uni-icons>
			
			<!-- 、右侧的文本 -->
			<text class="cart-title-text">购物车</text>
		</view>
		<!-- 循环渲染购物车中的商品信息 -->
		<uni-swipe-action>
			<block class="goodsshop" v-for="(goods,i) in cart" :key='i'>
				<uni-swipe-action-item :options="options" @click="swipeitemClickHandler(goods)">
					<my-goods :goods="goods" :showRadio="true" @radio-change="radioChangeHandler" :showNum="true" @num-change="numberChangeHandler"></my-goods>
					</uni-swipe-action-item>
			</block>
		</uni-swipe-action>
		<!-- 使用自定义的结算组件 -->
		<my-pay></my-pay>
	</view>
	
	<!-- 空白购物车的区域 -->
<view class="empty-car" v-else>
<image src="/static/empty.jpg"   class="empty-img"></image>
<text class="tips">空空如也~</text>
</view>
</template>

<script>
	import badegeMix from '@/minxins/tabbar-badge.js'
	import { mapState,mapMutations} from 'vuex'
	export default {
		mixins:[ badegeMix ],
		computed:{
			...mapState('m_cart',['cart'])
		},
		data(){
			return {
				options:[{
					text:'删除',
					style:{
						backgroundColor:'#C00000'
					}
				}]
			}
		},
		
		methods:{
			...mapMutations('m_cart',['upDategoodsState','upDategoodsCount']),
			radioChangeHandler(e){
				// console.log(e)
				this.upDategoodsState(e)
			},
			numberChangeHandler(e){
			this.upDategoodsCount(e)
			},
			swipeitemClickHandler(goods){
				this.removeGoodsByID(goods.goods_id)
			}
		}
	}
</script>

<style lang="scss">
	.car-boxbox{
		padding-bottom: 50px;
	}
.cart-title{
	height: 80rpx;
	display: flex;
	align-items: center;
	padding-left: 10rpx;
	border-bottom: 1px solid #07C160;
	.cart-title-text{
		font-size: 14px;
		margin-left: 10px;
	}
	
}

.empty-car{
		display: flex;
		flex-direction: column;
		align-items: center;
		padding-top: 150px;
		.empty-img{
			width: 120px;
			height: 120px;
		}
		.tips{
			font-size: 15px;
			font-weight: 700;
			color: gray;
			margin-top: 15px;
		
			
		}
	}
</style>
